import request from '@/api/config/request'
import { ApiResponse } from './type'

export interface CategoryData {
  id: number,
  name: string,
  createdAt?: string
}
export interface CategoryList {
  category: CategoryData[];
  total: number;
}
export interface Params {
  name?: ''
  pageNum: number;
  pageSize: number;
}

export interface CategoryAllList {
  id:number,
  name:string
}
// 获取全部类目分页
export const getCategory = (data: Params): Promise<ApiResponse<CategoryList>> => {
  return request.post('/category/find', data)
}
// 获取全部类目不分页
export const getAllCategory = (): Promise<ApiResponse<CategoryAllList[]>> => {
  return request.post('/category/findAll')
}

// 添加新类目 Omit 排除id
export const addNewCategory = (data: Omit<CategoryData, 'id'>): Promise<ApiResponse<null>> => {
  return request.post(
    '/category/add',
    data
  )
}

// 删除指定菜单
export const removeCategoryByID = (id: number): Promise<ApiResponse<null>> => {
  return request.delete(`/category/${id}`)
}

// 更新指定菜单
export const updateCategoryByID = (id: number, data: CategoryData): Promise<ApiResponse<null>> => {
  return request.patch(`/category/${id}`, data)
}
